package com.jeff.cryptor.lib;

import android.content.Context;
import android.util.Log;

/**
 * Author: duff
 * Date: 2018/11/15
 * Version: 1.0.0
 * Description: 加密解密，对外调用
 */
public final class Cryptor {

    /**
     * Check is valid app call.
     *
     * @param context
     * @return
     */
    public static boolean verify(Context context) {
        int result = AESNative.verify(context);
        if (result == -1) {
            Log.d("jeff", "[verifySign] Invalid application.");
        } else if (result == -2) {
            Log.d("jeff", "[verifySign] Invalid keystore.");
        }
        return result == 1;
    }

    public static String encrypt(Context context, String data) {
        if (verify(context))
            return AESNative.encrypt(data);
        throw new RuntimeException("Verify failed.");
    }

    public static String decrypt(Context context, String data) {
        if (verify(context))
            return AESNative.decrypt(data);
        throw new RuntimeException("Verify failed.");
    }

}